<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Akun extends CI_controller{
	
	function __construct(){
	parent::__construct();
	$this->load->model('akun_model');
	}
   
	function index()
	{
      
	}
	
	function registrasi($status)
	{
		if($status=='true')
		{
			if($this->input->post())
			{
				$this->akun_model->insert_user($this->input->post('name'), $this->input->post('pass2'), $this->input->post('email'));
				$alerts[] = array('error', 'Akun sudah didaftarkan,konfirmasi pengaktifan akun akan dikirimkan melalui email anda!');
				$this->session->set_flashdata('alerts', $alerts);
				redirect('kuesioner/list_kuesioner');
			} else
				{
				
				}
			
		} else 
			{
				$this->load->view('daftar');
			}
	
	}
	
	function cek_session(){	
		$kode_role = $this->session->userdata('username');
		if($kode_role == NULL){
			redirect('otent');
		}
	 }
	 
	 function edit_profil($status, $id)
	 {
		if($status == 'false')
		{
		$data['data_user'] = $this->akun_model->get_user_byid($id);
		$this->load->view('edit_profil', $data);
		} else
			{
				if($this->input->post('pass2') == '')
				{
					$this->akun_model->update_profil1($this->input->post('email'), $id);
					if($this->session->userdata('role') == 0)
					{
						redirect('admin/list_user');
					} else
						{
							redirect('kuesioner/list_kuesioner');
						}
				} else
					{
						$this->akun_model->update_profil2($this->input->post('pass2'), $this->input->post('email'), $id);
						if($this->session->userdata('role') == 0)
						{
							redirect('admin/list_user');
						} else
							{
								redirect('kuesioner/list_kuesioner');
							}
					}
			}
	 }
	
	
	function cek_username()
	{
		$nama = $_POST['username'];
		$username = $this->akun_model->cek_username($nama);
		//echo $nama;
		if($username != null)
		{
			//var_dump($username);
			echo $nama;
		} else
			{
				//var_dump($_POST['username']);
				echo '';
			}
	}
}
?>